package com.tyf.easyEs.controller;


import com.tyf.common.utils.R;
import com.tyf.easyEs.mapper.StudentEsMapper;
import com.tyf.easyEs.model.Student;
import jakarta.annotation.Resource;
import org.dromara.easyes.core.conditions.select.LambdaEsQueryWrapper;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@RestController
@RequestMapping("/esStudent")
public class StudentEsController {

    @Resource
    StudentEsMapper studentEsMapper;

    @GetMapping("/createIndex")
    public R createIndex(){
        studentEsMapper.createIndex();
        return R.ok();
    }

    @RequestMapping("/getList")
    public R getList(Student student){
        LambdaEsQueryWrapper<Student> studentLambdaEsQueryWrapper = new LambdaEsQueryWrapper<Student>();
        studentLambdaEsQueryWrapper.like(Student::getName,student.getName());
        List<Student> students = studentEsMapper.selectList(studentLambdaEsQueryWrapper);
        return R.ok(students.toString());
    }

    @PostMapping("/save")
    public R save(@RequestBody Student student){
        studentEsMapper.insert(student.addBirthday());
        return R.ok();
    }

    @PostMapping("/edit")
    public R edit(@RequestBody Student student){
        studentEsMapper.updateById(student);
        return R.ok();
    }

}
